package atndTwitter

object TwitterUtil{

  def getXML(url:String):xml.Elem = {
    val x = xml.XML.load( new java.net.URL( url ) )
    val error = x \\ "error" 
    if((error size) > 0)
    	throw new Exception(error text)
    else
    	x
  }

  def getFriends( screenName: String ,count:Int = 100 ):Seq[TwitterUser] = {
    val x = getXML( "http://api.twitter.com/1/friends/ids.xml?screen_name=" + screenName )

    val ids = x \\ "id" map{_.text}

    ids.take(count).map{ id =>
      TwitterUser( getXML("http://api.twitter.com/1/users/show.xml?user_id=" + id ) \ "screen_name" text)
    }
  }

  case class TwitterUser(
          screenName: String
  ){}

}            